var radioselected = 0;
function enableLink(){
	document.getElementById('link').disabled=false;
	document.getElementById('linkdesc').disabled=false;
	document.getElementById('imagefile').disabled=true;
	document.getElementById('videourl').disabled=true;
	radioselected = 1;
}
function enableImage(){
	document.getElementById('link').disabled=true;
	document.getElementById('linkdesc').disabled=true;
	document.getElementById('imagefile').disabled=false;
	document.getElementById('videourl').disabled=true;
	radioselected = 2;
}
function enableVideo(){
	document.getElementById('link').disabled=true;
	document.getElementById('linkdesc').disabled=true;
	document.getElementById('imagefile').disabled=true;
	document.getElementById('videourl').disabled=false;
	radioselected = 3;
}
function disableAll(){
	document.getElementById('link').disabled=true;
	document.getElementById('linkdesc').disabled=true;
	document.getElementById('imagefile').disabled=true;
	document.getElementById('videourl').disabled=true;
	radioselected = 0;
}
function showPreview(){
	var title = '<p style="font-weight: bold;font-size: 30px;">' + document.getElementById('title').value + '</p>';
	var postcontent;
	var d = new Date();
	var date = d.getDate();
	var month = d.getMonth();
	var year = d.getFullYear();
	var time = d.toLocaleTimeString();
	var postingtime = date + '/' + month + '/' + year + ' ' + ' at ' + time;
	
	document.getElementById('preview').innerHTML = "";
	
	switch(radioselected){
		case 1:{
				//link
				postcontent = title + 
				'<div><span>posted by </span><span id="content-poster" class="commentator">Anonymous</span><div class="dateformat">' + postingtime + '</div></div>'
				+ '<p style="left-margin:30px;">' + document.getElementById('linkdesc').value + '<br/>URL : <a href="' + document.getElementById('link').value + '">' + document.getElementById('link').value + '</a></p>';
				break;
		}
		case 2:{
				//image
				/*
				var newimg = document.createElement("IMG");
				var fileimg = document.getElementById('imagefile');
				var imgfiles = fileimg.value;
				alert('coooi');
				newimg.src = imgfiles[0].getAsDataURL();
				alert('oooi');
				document.getElementById('preview').appendChild(newimg);
				*/
				var imgurl = "tenggelam.jpg";
				postcontent = title + 
				'<div><span>posted by </span><span id="content-poster" class="commentator">Anonymous</span><div class="dateformat">' + postingtime + '</div></div>'
				+ '<div class="imagevideo"><img src="' + imgurl + '" width="420" height="345" alt="preview_picture"></img></div>';
				break;
		}
		case 3:{
				//video
				var url = document.getElementById('videourl').value;
				var newurl = url.toString().replace("watch?v=", "v/");
				postcontent = title + 
				'<div><span>posted by </span><span id="content-poster" class="commentator">Anonymous</span><div class="dateformat">' + postingtime + '</div></div>'
				+ '<div class="imagevideo"><embed width="420" height="345" src="' + newurl + '" type="application/x-shockwave-flash"></embed></div>';
				break;
		}
		default:{
				break;
		}
	}
	document.getElementById('preview').innerHTML = postcontent;
}